package com.fullstack.server.modules

import cats.effect.Resource
import cats.effect.kernel.{Async, Sync}
import com.fullstack.server.config.PostgresConfig
import doobie.hikari.HikariTransactor
import doobie.util.ExecutionContexts

object Database {

  def makePostgresResource[F[_]: Async](config: PostgresConfig): Resource[F, HikariTransactor[F]] =
    for {
      ec <- ExecutionContexts.fixedThreadPool(config.nThread)
      xa <- HikariTransactor.newHikariTransactor[F](
        "org.postgresql.Driver",
        config.url,
        config.username,
        config.password,
        ec
      )
    } yield xa

}
